<!DOCTYPE html>
<html lang="en">
<!--Vue实例所控制的这个元素区域，就是我们的V-->
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Title</title>
    <script src="./lib/vue.js"></script>
    <script src="./lib/vue-resource.js"></script>
    <link rel="stylesheet" href="./lib/bootstrap.min.css">
</head>
<body>
<div id="app">
    <div class="panel panel-primary">
        <div class="panel-heading">
            <h3 class="panel-title">添加品牌</h3>
        </div>
        <div class="panel-body form-inline">
            <label>
                Id:
                <input type="text" v-model="id">
            </label>
            <label>
                Name:
                <input type="text" v-model="name" class="form-control">
            </label>
            <input type="button" value="添加" @click="add" class="btn btn-primary">
        </div>
    </div>
    <table class="table table-bordered table-hover table-striped">
        <thead>
        <tr>
            <th>Id</th>
            <th>Name</th>
            <th>Ctime</th>
            <th>Operation</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="item in list" :key="item.id">
            <td>{{item.id}}</td>
            <td>{{item.name}}</td>
            <td>{{item.ctime}}</td>
            <td>
                <a href="">删除</a>
            </td>
        </tr>
        </tbody>
    </table>
</div>
<body>
<script>
    Vue.http.options.root = 'http://vue.studyit.io/';
    Vue.http.options.emulateJSON = true;
    // 创建Vue实例，得到ViewModel
    var vm = new Vue({
        el: '#app',
        data: {
            name: '',
            list: [
                {id: 1, name: '五菱宏光', ctime: new Date()},
                {id: 2, name: '众泰', ctime: new Date()},
            ]
        },
        created(){ // 当vm实例的data和methods 初始化完毕后，vm会自动自动
            this.getAllList()
        },
        methods: {
            add(){},
            getAllList(){ //获取所有品牌列表
                //分析：
                //1,由于已经导入 Vue-resource 这个包，所以可以直接通过 this.$http 来发起数据请求
                //2,根据接口API文档，知道，获取列表的时候，应该发起一个get 请求
                this.$http.get('api/getprodlist').then(result =>{
                    if (result.status === 0){
                        this.list = result.message
                    }else {
                        alert('获取数据失败！')
                    }
                })
            }
        },
    })
</script>
</body>
</html>